#include "clueCardRegister.h"
#include "stringUtils.h"
#include "jsonUtils.h"
#include "httpOutput.h"
#include "showClueCardHandler.h"
#include "clearClueCardHandler.h"

void ClueCardRegister::registerHandler(httplib::Server& svr)
{
	svr.Post("/showClueCard", [](const httplib::Request& req, httplib::Response& res) {
		int64_t id=0;
		int channel=0;
		String body = StringUtils::utf8_2_wstr(req.body.c_str(), req.body.length());
		JsonDoc doc(rapidjson::kObjectType);
		doc.Parse(body.c_str());
		JsonUtils::loadLong(doc, L"id", id);
		JsonUtils::loadInt(doc, L"channel", channel);
		ShowClueCardHandler handler(id, channel);
		handler();
		HttpOutput::outputJson(L"{\"success\":true}", res);
	});
	svr.Delete("/clearClueCard", [](const httplib::Request& req, httplib::Response& res) {
		int64_t movieId=0, clueCardId=0;
		int channel=0;
		String clueCardType;
		String body = StringUtils::utf8_2_wstr(req.body.c_str(), req.body.length());
		JsonDoc doc(rapidjson::kObjectType);
		doc.Parse(body.c_str());
		JsonUtils::loadLong(doc, L"movieId", movieId);
		JsonUtils::loadLong(doc, L"clueCardId", clueCardId);
		JsonUtils::loadStr(doc, L"clueCardType", clueCardType);
		JsonUtils::loadInt(doc, L"channel", channel);
		ClearClueCardHandler handler;
		handler(movieId, clueCardId, channel,clueCardType);
		HttpOutput::outputJson(L"{\"success\":true}", res);
	});
}
